package org.ihelpuoo.core;

import org.ihelpuoo.lang.ConfigException;
import org.ihelpuoo.lang.NutException;
import org.ihelpuoo.util.Properties;

/**
 * <b>Factory class:</b>
 * <hr color=grey size=1>
 *
 *
 *
 * @author zozoh  created @ 2006
 *
 */
public abstract class Factory implements Initializeble
{
	protected Properties	config;
	protected Nut			nut;

	public Nut nut()
	{
		return nut;
	}

	public void setNut(Nut nut)
	{
		this.nut = nut;
	}

	public Properties getConfig()
	{
		return config;
	}

	protected void setConfig(Properties config)
	{
		this.config = config;
	}

	public String getProperty(String key, String defaultValue)
	{
		if (null == config)
			return null;
		return config.getString(key,defaultValue);
	}

	public String getProperty(String key)
	{
		if (null == config)
			return null;
		return config.getString(key);
	}

	public String getPropertyTrimed(String key, String defaultValue)
	{
		if (null == config)
			return null;
		return config.getStringTrimed(key,defaultValue);
	}

	public String getPropertyTrimed(String key)
	{
		if (null == config)
			return null;
		return config.getStringTrimed(key);
	}

	public abstract void depose() throws NutException;

	public void init(Properties config) throws NutException
	{
		if (null == config)
			throw new ConfigException("Factory config file is NULL");

		this.config = config;
	}
}
